package com.wxgo.controller.admin;

import java.util.List;

import com.jfinal.core.Controller;
import com.wxgo.common.model.Role;
import com.wxgo.factory.DaoFactory;

public class RoleController extends Controller {
	public void manage() {
		List<Role> roleList = DaoFactory.roleDao().find("select * from role");
		setAttr("tableList", roleList);
		render("/admin/role/roleManage.html");
	}

	public void add() {
		render("/admin/role/roleAdd.html");
	}

	public void save() {
		Role role = getModel(Role.class, "role");
		role.save();
		manage();
		return;
	}

	public void delete() {
		String id = getPara("id");
		DaoFactory.roleDao().delete("role", id);
		manage();
	}

	public void edit() {
		Integer id = getParaToInt("id");
		Role role = DaoFactory.roleDao().findById(id);
		setAttr("role", role);
		render("/admin/role/roleEdit.html");
	}

	public void update() {
		Role role = getModel(Role.class, "role");
		role.update();
		manage();
		return;
	}
}
